import * as apiService from '@/services/api';

/**
 * 取得返水策略列表
 * @param params
 * @returns {Promise<*>}
 */
const marketingRebateListApi = params => apiService.post(api.MARKETING_REBATE_SETTING_LIST,
  params);

/**
 * 切换返水策略状态
 * @param id
 * @param type
 * @returns {Promise<*>}
 */
const marketingRebateToggleApi = ({ id, type }) => apiService.post(api.MARKETING_REBATE_STATUS_TOGGLE,
  { id, type });

/**
 * 新建/保存返水策略
 */
const marketingRebateSaveApi = params => apiService.post(api.MARKETING_REBATE_SETTING_SAVE,
  params);

/**
 * 返水策略详情
 * @param id
 * @returns {Promise<*>}
 */
const marketingRebateDetailApi = id => apiService.post(api.MARKETING_REBATE_SETTING_DETAIL, { id });

/**
 * 删除返水策略
 * @param params
 * @returns {Promise<*>}
 */
const marketingRebateDeleteApi = ({ id }) => apiService.post(api.MARKETING_REBATE_SETTING_DELETE,
  { id });

/**
 * 返水记录
 * @param params
 * @returns {Promise<*>}
 */
const marketingRebateLogListApi = params => apiService.post(api.MARKETING_REBATE_LOG_LIST,
  params);

/**
 * 优惠活动列表
 * @param params
 * @returns {Promise<*>}
 */
const marketingOfferListApi = params => apiService.post(api.MARKETING_OFFER_LIST,
  params);
/**
 * 优惠活动栏位展示下拉列表
 * @param params
 * @returns {Promise<*>}
 */
const marketingOfferDropListApi = params => apiService.post(api.MARKETING_OFFER_DROP_LIST,
  params);
/**
 * 新建/保存优惠活动
 */
const marketingOfferSaveApi = (params) => {
  const {
    id, startTime, endTime, showStartTime, showEndTime, actType, name, actId, gameType, showClient, pcImage, pcIndexImage, pcUrl, h5Image, h5IndexImage, h5Url, sportImage, sportIndexImage, sportUrl, indexAct, applicablePlatformAlias,
  } = params;
  if (_.isUndefined(id)) {
    return apiService.post(api.MARKETING_OFFER_SAVE,
      {
        startTime,
        endTime,
        showStartTime,
        showEndTime,
        actType,
        name,
        actId,
        gameType,
        showClient,
        pcImage,
        pcIndexImage,
        pcUrl,
        h5Image,
        h5IndexImage,
        h5Url,
        sportImage,
        sportIndexImage,
        sportUrl,
        indexAct,
        applicablePlatformAlias,
      });
  }
  return apiService.post(api.MARKETING_OFFER_UPDATE,
    {
      id,
      showStartTime,
      showEndTime,
      startTime,
      endTime,
      actType,
      name,
      actId,
      gameType,
      showClient,
      pcImage,
      pcIndexImage,
      pcUrl,
      h5Image,
      h5IndexImage,
      h5Url,
      sportImage,
      sportIndexImage,
      sportUrl,
      indexAct,
      applicablePlatformAlias,
    });
};

/**
 * 优惠活动详情
 * @param id
 * @returns {Promise<*>}
 */
const marketingOfferDetailApi = id => apiService.post(api.MARKETING_OFFER_DETAIL, { id });

/**
 * 删除优惠活动
 * @param params
 * @returns {Promise<*>}
 */
const marketingOfferDeleteApi = ({ id }) => apiService.post(api.MARKETING_OFFER_DELETE,
  { id });

/**
 * 启用/禁用活动
 * @param params
 * @returns {Promise<*>}
 */
const marketingOfferUpdateStatus = ({ id, status }) => apiService.post(api.MARKETING_OFFER_UPDATE_STATUS,
  { id, status });


/**
 * 活动资金统计列表
 * @param params
 * @returns {Promise<*>}
 */
const marketingOfferExpenditureListApi = params => apiService.post(api.MARKETING_OFFER_EXPENDITURE_LIST,
  params);

/**
 * 素材列表
 * @param params
 * @returns {Promise<*>}
 */
const marketingMaterialListApi = params => apiService.post(api.MARKETING_MATERIAL_LIST,
  params);


/**
 * 新建/保存广告
 */
const marketingMaterialSaveApi = params => apiService.post(api.MARKETING_MATERIAL_ADD, params);

/**
 * 删除广告
 * @param params
 * @returns {Promise<*>}
 */
const marketingMaterialDeleteApi = ({ id }) => apiService.post(api.MARKETING_MATERIAL_DEL,
  { id });
/**
 * 广告列表
 * @param params
 * @returns {Promise<*>}
 */
const marketingAdvertisementListApi = params => apiService.post(api.MARKETING_ADVERTISEMENT_LIST,
  params);

/**
 * 新建/保存广告
 */
const marketingAdvertisementSaveApi = (params) => {
  // const {
  //   id, startTime, endTime, bannerType, matchId, actionUrl, name, showClient, position, image, smallImage, video, theme, summary, content,
  // } = params;
  let params1 = _.cloneDeep(params);
  delete params1.time;
  if (params1.showClient === 0 || params1.bannerType === 0) {
    delete params1.matchId;
  }
  if (_.isUndefined(params1.id)) {
    return apiService.post(api.MARKETING_ADVERTISEMENT_SAVE,
      params1);
  }
  return apiService.post(api.MARKETING_ADVERTISEMENT_UPDATE,
    params1);
};

/**
 * 删除广告
 * @param params
 * @returns {Promise<*>}
 */
const marketingAdvertisementDeleteApi = ({ id }) => apiService.post(api.MARKETING_ADVERTISEMENT_DELETE,
  { id });
/**
 * 查询所有操作人
 * @param params
 * @returns {Promise<*>}
 */
const marketingAdvertisementOperatorApi = () => apiService.post(api.MARKETING_ADVERTISEMENT_OPERATOR);

/**
 * 启用/禁用广告
 * @param params
 * @returns {Promise<*>}
 */
const marketingAdvertisementUpdateStatus = ({ id, status }) => apiService.post(api.MARKETING_ADVERTISEMENT_UPDATE_STATUS,
  { id, status });

/**
 * 获取修改人
 * @returns {Promise<*>}
 */
const marketingOperatorApi = () => apiService.post(api.MARKETING_OPERATOR);

// /gl/system/domain/manage/add
/**
 * 域名列表
 * @param params
 * @returns {Promise<*>}
 */
const sysDomainListApi = params => apiService.post(api.SYS_DOMAIN_LIST,
  params);

/**
 * 新建 域名
 */
const sysDomainAddApi = (params) => {
  const { domain, type, clientType } = params;
  return apiService.post(api.SYS_DOMAIN_ADD, { domain, type, clientType });
};

/**
 * 删除域名
 * @param params
 * @returns {Promise<*>}
 */
const sysDomainDeleteApi = ({ id }) => apiService.post(api.SYS_DOMAIN_DEL,
  { id });

/**
 * 保存首页活动配置
 * @param params
 * @returns {Promise<*|*|*|undefined>}
 */
const marketingOfferSaveHomeGameApi = params => apiService.post(api.MARKETING_OFFER_SAVE_HOME_GAME,
  params);

/**
 * 获取首页活动配置
 * @returns {Promise<*|*|*|undefined>}
 */
const marketingOfferGetHomeGameApi = () => apiService.post(api.MARKETING_OFFER_GET_HOME_GAME);
export {
  marketingRebateSaveApi,
  marketingRebateListApi,
  marketingRebateDetailApi,
  marketingRebateToggleApi,
  marketingRebateDeleteApi,
  marketingRebateLogListApi,

  marketingOfferListApi,
  marketingOfferDropListApi,
  marketingOfferSaveApi,
  marketingOfferDetailApi,
  marketingOfferDeleteApi,
  marketingAdvertisementListApi,
  marketingAdvertisementSaveApi,
  marketingAdvertisementOperatorApi,
  marketingAdvertisementDeleteApi,
  marketingAdvertisementUpdateStatus,

  marketingOperatorApi,
  marketingOfferUpdateStatus,
  marketingOfferExpenditureListApi, //

  marketingMaterialListApi,
  marketingMaterialDeleteApi,
  marketingMaterialSaveApi,
  marketingOfferSaveHomeGameApi,
  marketingOfferGetHomeGameApi,

  // 域名管理
  sysDomainListApi,
  sysDomainAddApi,
  sysDomainDeleteApi,
};
